var statistics = function(host) {
    var getStringData = function (data) {
        let ary = [];
        for (let key in data) {
            if (Object.prototype.hasOwnProperty.call(data, key)) {
                let val = data[key];
                if (typeof val === 'object') {
                    val = JSON.stringify(val);
                }
                ary.push(`${key}=${encodeURIComponent(val)}`);
            }
        }
        return ary.join('&');
    }
    return {
        sendLog: function(data, isError) {
            const sendUrl = `//${host}/${isError ? 'e.gif' : 'p.gif'}?`;
            const SEED_NUM = 16777216;
            let img = new Image();
            // 生成随机数，16777216为2的24次方
            let imgId = `img${Math.random() * (SEED_NUM) | 0}`;
            // new Image()赋给全局变量，防止图片请求未建立时，垃圾回收机制回收new Image()，导致请求取消、打点丢失
            window[imgId] = img;
            let cbFn = () => {
                window[imgId] = null;
            };
            img.onload = cbFn;
            img.onerror = cbFn;
            img.src = sendUrl + getStringData(data);
        },
        sendError: function(data) {
            this.sendLog(data, true);
        }
    }
}
